package com.zzyl.controller;

import com.aliyun.iot20180120.models.*;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/iot")
@Api(tags = "管理端 - 物联网iot相关接口")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /**
     * 同步物联网平台产品列表
     * @return
     */
    @PostMapping("/syncProductList")
    @ApiOperation("从物联网平台同步产品列表")
    public ResponseResult syncProductList(){
        deviceService.syncProductList();
        return success();
    }

    /**
     * 查询所有产品列表
     * @return
     */
    @GetMapping("/allProduct")
    @ApiOperation("查询所有产品列表接口")
    public ResponseResult<List<ProductVo>> allProduct(){
        List<ProductVo> productVoList = deviceService.allProduct();
        return success(productVoList);
    }

    /**
     * 注册设备
     * @param deviceDto
     * @return
     */
    @PostMapping("/RegisterDevice")
    @ApiOperation("注册设备接口")
    public ResponseResult registerDevice(@RequestBody DeviceDto deviceDto){
        deviceService.registerDevice(deviceDto);
        return success();
    }

    /**
     * 分页查询设备列表
     * @param devicePageQueryDto
     * @return
     */
    @GetMapping("/pageQueryDevice")
    @ApiOperation("分页查询设备列表接口")
    public ResponseResult<PageResponse<DeviceVo>> pageQueryDevice(DevicePageQueryDto devicePageQueryDto){
        PageResponse<DeviceVo> pageResponse = deviceService.pageQueryDevice(devicePageQueryDto);
        return success(pageResponse);
    }

    /**
     * 查询设备详细数据
     * @param request 查询设备详情请求模型
     * @return 设备详细数据
     */
    @PostMapping("/QueryDeviceDetail")
    @ApiOperation("查询设备详细数据接口")
    public ResponseResult<DeviceVo> queryDeviceDetail(@RequestBody QueryDeviceDetailRequest request){
        DeviceVo deviceVo = deviceService.queryDeviceDetail(request);
        return success(deviceVo);
    }

    /**
     * 查询指定设备的物模型运行状态
     * @param request
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation("查询指定设备的物模型运行状态接口")
    public ResponseResult QueryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){
        return success(deviceService.QueryDevicePropertyStatus(request));
    }

    /**
     * 查看指定产品的已发布物模型中的功能定义详情
     * @param request
     * @return
     */
    @PostMapping("/QueryThingModelPublished")
    @ApiOperation("查看指定产品的已发布物模型中的功能定义详情")
    public ResponseResult QueryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request){
        return success(deviceService.QueryThingModelPublished(request));
    }

    /**
     * 修改设备备注名称
     * @return
     */
    @PostMapping("/UpdateDevice")
    @ApiOperation("修改设备备注名称")
    public ResponseResult UpdateDevice(@RequestBody DeviceDto deviceDto){
        deviceService.UpdateDevice(deviceDto);
        return success();
    }

    /**
     * 删除设备
     * @param deviceDto
     * @return
     */
    @DeleteMapping("/DeleteDevice")
    @ApiOperation("删除设备")
    public ResponseResult DeleteDevice(@RequestBody DeviceDto deviceDto){
        deviceService.DeleteDevice(deviceDto);
        return success();
    }
}
